package com.dcloud.file.service.impl;

import cn.hutool.core.util.IdUtil;
import com.dcloud.file.enums.BizCodeEnum;
import com.dcloud.file.exception.BizException;
import com.dcloud.file.service.FileService;
import com.dcloud.file.util.CustomFileUtil;
import io.minio.GetPresignedObjectUrlArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.http.Method;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.MinioUtil;
import org.jeecg.config.oss.MinioConfig;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.TimeUnit;


@Service
@Slf4j
public class MinioFileServiceImpl implements FileService {


    @Override
    public Result upload(MultipartFile file) {
        try {
            String fileUrl =  MinioUtil.upload(file,"");
            return Result.ok(fileUrl);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }


    @Override
    public InputStream getFile(String fileName) {
        return MinioUtil.getMinioFile(MinioUtil.getBucketName(), fileName);
    }

}
